home *** CD-ROM | disk | FTP | other *** search
/ Double-Click / Double Click - Issue 1 (Pentrisoft).adf / Mag1 / DiskMag.doc < prev    next >
Text File  |  1993-09-23  |  2KB  |  30 lines

  1. \s2 DoubleClick!
  2.  
  3. I was wondering what article I could possibly write for the first issue of \s2 DoubleClick! \s0 when I thought, why not explain how I wrote the viewing program for this disk-mag.
  4.  
  5. Firstly, you may ask, why writing one myself at all? Mainly because I didn't think much of the existing disk-mag creators, and using AmigaGuide would have been boring. Actually, I originally wrote this for a roleplaying game that I am writing, and converted it from that.
  6.  
  7. The language I used to write this was AMOSPro, but this ought to be relevant to all programmers.
  8.  
  9. Firstly, I must explain that I split the process into two main areas (procedures in AMOS). One to load in the text, and prepare it, and another to actually display the text, and read the buttons. I will cover the former in this issue.
  10.  
  11. If you've looked at the disk contents, you'll have seen how each section is stored as a separate text file, in ASCII format, but with special `codes' to signify italics, graphics, hypertext, etc. The required file is loaded of the disk straight into a string variable. The actual code is something like this:
  12.  
  13.   Open In 1,FILE$  -  Open up the required file
  14.   T$=Input$(1,Lof(1))  -  This moves the contents of the file into the variable T$. Lof(1) returns the length of the file.
  15.   Close 1  -  Just to close it again.
  16.  
  17. The next step is a crucial one. It's no good displaying the entire file all at once; if, for example, the user pages down to line 41, you need to know at what position in the text line 41 starts. To do this, we create an array called LPOS, such that LPOS(41) will return the position in T$ where line 41 begins.
  18.  
  19. The way this is done is that I search through the text in blocks. If a new paragraph/line is signified (by ASCII code 10) BEFORE the end of line is reached, then the current line will be cut off at that point, and a new one begun. Otherwise, we search through, jumping a word at a time (by searching for spaces), until the number of characters over-runs onto the next line; then we start a new line. The code is something along these lines:
  20.  
  21.   E$=Chr$(10)
  22.   LPOS(1)=0
  23.   C=1
  24.   CPOS=0
  25.   Do
  26.      E=Instr(Mid$(T$,LPOS(C),PGWID),Chr$(0))
  27.      T=Instr(Mid$(T$,LPOS(C),PGWID+1),E$)
  28.      If T=0
  29.         K=LPOS(C)
  30.         FL=Instr(T$,K,PGWID-K+LPOS(C)),"[")